#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QLabel>
#include <QPushButton>
#include <QUdpSocket>
#include <QTcpSocket>
#include <QTcpServer>
#include <QTimer>
#include <QMenu>
#include <QPointer>
#include <QMap>
#include <QTranslator>

#include "qrawsocket.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_statusRstBtnClicked();
    void on_pushButtonOpen_clicked();
    void onDataReceived();
    void on_pushButtonSend_clicked();
    void on_checkBoxSendHex_stateChanged(int arg1);
    void timeUpDate();
    void on_plainTextEditRecv_textChanged();
    void on_plainTextEditRecv_customContextMenuRequested();
    void clearRecv();
    void saveRecv();
    void onTcpConnected();
    void onTcpDisconnected();
    void onTcpError(QAbstractSocket::SocketError err);
    void onNewTcpConnect();
    void on_pushButtonAddrList_clicked();
    void on_comboBoxProtoChanged();
    void on_checkBoxShowTime_stateChanged(int checked);
    void on_checkBoxSendFile_stateChanged(int checked);
    void on_checkBoxToFile_stateChanged(int checked);
    void showAbout();
    void showAboutQt();
    void setLanguage(QAction *action);

private:
    Ui::MainWindow *ui;
    QLabel *statusTx;
    QLabel *statusRx;
    QPushButton *statusRstBtn;
    quint64 rx;
    quint64 tx;
    QTimer timer;
    quint32 sequence;

    QPointer<QUdpSocket> udpSock;
    QPointer<QTcpSocket> tcpSock;
    QPointer<QTcpServer> tcpServer;
    QPointer<QRawSocket> rawSock;

    QMenu *recvMenu;
    QMap<QTcpSocket *, int> tcpClients;

    QString sendFile;
    QString toFile;

    QMenu *languageMenu;
    QAction *langAuto;
    QAction *about;
    QAction *aboutQt;
    QAction *clear;
    QAction *save;

    void doSend();
    void InitLocalIP();
    void closeSock();
    bool isOpened();
    void initUi();
};

#endif // MAINWINDOW_H
